<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css">
  	<script type="text/javascript" src="../js/jquery.js"></script>
  	<script type="text/javascript" src="../js/script.js"></script>
</head>
<body>
<div id="boxbody">
<div id="boxall">
<?php
	
	$searchedname=$_REQUEST["searchedname"];
	if($searchedname==="")
		echo "Insert a Summoner name, please!";
	else{
	/**
	connessione database
	*/
				
	$connessione = mysql_connect("localhost","root","","LOL") or die("Connessione al database fallita");
 	mysql_select_db('LOL',$connessione); 
	//if($connessione) echo "connesione stabilita";
 	$sqlplayer="SELECT * FROM player WHERE username = '$searchedname'" ;
 	$resultplayer= mysql_query($sqlplayer);
 	$datiplayer=0;
 	if(!$resultplayer)
 		die("Esequzione della query fallita".mysql_error());
 	if(mysql_num_rows($resultplayer) == 0){
 		echo "Il giocatore ".$searchedname." NON ESISTE. Controllare il giocatore inserito<BR>";
 	}
 	else{
 		$datiplayer =mysql_fetch_assoc($resultplayer);
 		
 		
 	}
	$sql = "select *
			 from statistichep as s inner join partita as p 
 			on s.partita= p.idpartita
 			 where player = '$searchedname' 
			order by s.partita desc ";
	
	/*
	echo "<br><br><br><br><br><br><br>";
	echo "<br>".$sql;
	echo "<br><br><br><br><br><br><br>";*/
	$result= mysql_query($sql);
	if(!$result)
		die("Esequzione della query fallita".mysql_error());
	if(mysql_num_rows($result) == 0){
		echo "Non ci sono partite Giocate dal ".$searchedname;
	}
	else{
		//stampa intestazione
		/**
		 * STAMPA RIGA PARTITA
		 */
		$row=mysql_fetch_assoc($result);
		echo "<div class=\"boxplayer\" style=\"Background:url(../img/skinmodificato/$row[champion].jpg) top right no-repeat;\">
		<div class=\"boxiconaplayer\"><img class=\"summnerimg\" src=\"../img/summunericon.jpg\"></div>
		<div class=\"datiplayerbox\">
		<div id=\"playernametd\" >$datiplayer[username]</div>
		<div   style=\"color:GOLD;\">Livello $datiplayer[livello] </div>
		<form name=\"returnhome\" action=\"index.php\" method=\"get\">
		<input type=\"submit\" value=\"Return\">
		</form>
		</div>
		</div>";
		$nrow = 0;
		mysql_data_seek($result,0);
		while($row=mysql_fetch_assoc($result)){
			if($row['result'])
				echo "<div class=\"riga$row[partita]\" id=\"riga\" style=\"background-color:#005B18;\"><div class=\"boxstatistichep\"><table class=\"statistichetable\"><tr class=\"statistichetr\">";
			else
				echo "<div class=\"riga$row[partita]\" id=\"riga\"	 style=\"background-color:#650018;\"><div class=\"boxstatistichep\"><table class=\"statistichetable\"><tr class=\"statistichetr\">";

			//stampa champion con icona
			echo "<td  class=\"imgchamptd\"><a href=\"http://127.0.0.1/loldb/php/showskill.php?champion=$row[champion]\"><img src=\"../img/champion/$row[champion].png\"  alt=\"\" /></a></td>";
			echo "<td  class=\"namechamptd\">$row[champion]</td>";
			echo "<td  class=\"datatd\">$row[data]<br>$row[ora]</td>";
			echo "<td  class=\"dutaratd\">Durata <br> $row[durata] min</td>";
			echo "<td  class=\"scoretd\"><table><tr><td>Kills : $row[kills]</td></tr>";
			echo "<tr><td>Deaths : $row[deaths]</td></tr>";
			echo "<tr><td>Mostri : $row[score]</td></tr></table></td>";
			echo "<td  class=\"damagetd\"><table><tr><td>Danno inflitto : $row[damagedealt]</td></tr>";
			echo "<tr><td>Danno ricevuto : $row[damageReceived]</td></tr></table></td>";
			if($row['result'])
				echo "<td  class=\"resulttd\">VITTORIA</td>";
			else 	
				echo "<td  class=\"resulttd\">SCONFITTA</td>";
			echo "</td>";
			echo"<td><form action=\"stampdivsquadraitem();\">
					    <input type=\"button\" class=\"riga$row[partita]\"  id=\"bottondettagli\"  value=\"Dettagli\">
					</form>
				</td></tr></table></div></div>";
			
			$nrow++;
		}
		
		/**
		 * FINE STAMPA
		 */
	mysql_free_result($result);
	mysql_close();

	/*
	fine connessione
	*/
	}
}
?> 

	<form name="returnhome" action="index.php" method="get">
		<input type="submit" value="Return">
	</form>
</div>
</div>
</body>
</html>